package www.test.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;



import sun.misc.BASE64Encoder;

public class TokenProcess
{
	private TokenProcess(){}
	private  static TokenProcess instance = new TokenProcess();
	//返回类对象
	public static TokenProcess getInstance()
	{
		return instance;
	}
	//生成token
	public static String makeToken() 
	{
		String token =(System.currentTimeMillis()+new Random().nextInt(99999999))+"";
		try
		{
			MessageDigest md = MessageDigest.getInstance("md5");
			byte md5[] = md.digest(token.getBytes());
			BASE64Encoder encoder = new BASE64Encoder();
			return encoder.encode(md5);
		}
		
		catch (NoSuchAlgorithmException e)
		{
			throw new RuntimeException(e);
		}
		
		
	}
	
	public static void main(String[] args)
	{
		for(int i = 0 ;i < 10 ; i ++)
		{
			String a = makeToken();
			System.out.println(a);
			
		}
		
	}

}
